﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Empires.CRL.DataContract;

namespace Empires.PL.Web.Controllers
{
    public static class InjectMessage
    {
        public static void InjuectProcessMessage<T>(this T model, string message) where T : BaseModel
        {
        }
        /// <summary>
        /// 添加一个操作成功的提示，该提示将在2s后淡出
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        public static void InjuectProcessSuccessMessage<T>(this T model) where T : BaseModel
        {
            string message = "<div id=\"processmsgbox\"  style=\"height:20px; padding-top:5px; background-color:Green; text-align:center; color:White; font-weight:bold;\">操作成功</div><script type=\"text/javascript\">window.setTimeout(function () {$('#processmsgbox').fadeOut(800, function () { });}, 2000);</script>";
            (model as BaseModel).SuccessMessage += message;
        }

        public static void InjuectRedrectScript<T>(this T model, string redrect) where T : BaseModel
        {
            string message = "<script type=\"text/javascript\">window.setTimeout(function () { window.location.href='" + redrect + "'; }, 2000);</script>";
            (model as BaseModel).SuccessMessage += message;
        }

        /// <summary>
        /// 添加一个操作失败的提示，该提示将在2s后淡出,msg长度不能超过20个字符,否则该变量会被替换成"操作失败"
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        public static void InjuectProcessFailMessage<T>(this T model, string msg) where T : BaseModel
        {
            msg = msg.Length > 22 ? "操作失败" : msg;
            string message = "<div id=\"processmsgbox\"  style=\"height:20px; padding-top:5px; background-color:Red; text-align:center; color:White; font-weight:bold;\">" + msg + "</div><script type=\"text/javascript\">window.setTimeout(function () {$('#processmsgbox').fadeOut(800, function () { });}, 2000);</script>";
            (model as BaseModel).SuccessMessage = message;
        }
    }
}